package com.wuyan.locationdog.view

import android.content.Context
import android.view.Gravity
import android.view.View
import android.widget.TextView
import androidx.appcompat.widget.AppCompatImageView
import com.arcsoft.commonbase.ext.gone
import com.wuyan.locationdog.R
import leifu.shapelibrary.ShapeView

import razerdp.basepopup.BasePopupWindow


class TipPopup(
    context: Context,
    var icon: Int,
    var title: String,
    var desc: String,
    var btnSure: String,
    var btnCancel: String? = null,
    var sureCallback: (() -> Unit)? = null,
    var cancelCallback: (() -> Unit)? = null,

    ) :
    BasePopupWindow(context) {



    init {
        contentView = createPopupById(R.layout.pop_device_tip)
        popupGravity = Gravity.CENTER
        setBackPressEnable(false)
        setOutSideDismiss(false)
        setOutSideTouchable(false)
    }

    override fun onViewCreated(contentView: View) {
        super.onViewCreated(contentView)
        findViewById<AppCompatImageView>(R.id.icon).setImageResource(icon)

        findViewById<TextView>(R.id.title).text = title
        findViewById<TextView>(R.id.desc).text = desc
        findViewById<ShapeView>(R.id.btnSure).apply {
            setText(btnSure)
            setOnClickListener {
                sureCallback?.invoke()
                dismiss()
            }
        }
        if (btnCancel.isNullOrEmpty()) {
            findViewById<TextView>(R.id.btnCancel).gone()
        }
        findViewById<TextView>(R.id.btnCancel).apply {
            setText(btnCancel)
            setOnClickListener {
                cancelCallback?.invoke()
                dismiss()
            }
        }


    }


}
